﻿<Window x:Class="DataBindingLab.AddProductWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:DataBindingLab" 
    Title="Add Product Listing"
    SizeToContent="WidthAndHeight"
    ResizeMode="NoResize"
    Loaded="OnInit"
    >

    <Window.Resources>
        <src:SpecialFeaturesConverter x:Key="specialFeaturesConverter" />
      <ControlTemplate x:Key="validationTemplate">
        <DockPanel>
          <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
          <AdornedElementPlaceholder/>
        </DockPanel>
      </ControlTemplate>
    </Window.Resources>

    <Border Padding="20">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
          </Grid.RowDefinitions>
          <Border BorderThickness="0,0,0,2" BorderBrush="Black" Padding="5" Grid.Row="0">
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="106"/>
                <ColumnDefinition Width="*"/>
              </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                               Style="{StaticResource titleStyle}"
                               Margin="5">Item for sale:</TextBlock>

                    <TextBlock Grid.Row="1" Grid.Column="0"
                               Style="{StaticResource smallTitleStyle}" Margin="0,5,0,5">Item Description:</TextBlock>
                    <TextBox Name="DescriptionEntryForm" Grid.Row="1" Grid.Column="1" 
                        Text="{Binding Path=Description, UpdateSourceTrigger=PropertyChanged}"
                        Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5"/>

                    <TextBlock Grid.Row="2" Grid.Column="0" Style="{StaticResource smallTitleStyle}" Margin="0,5,0,5">Start Price:</TextBlock>

              <TextBox Name="StartPriceEntryForm" Grid.Row="2" Grid.Column="1"
                  Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5">
                <TextBox.Text>
                  <Binding Path="StartPrice" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                      <ExceptionValidationRule />
                    </Binding.ValidationRules>
                  </Binding>
                </TextBox.Text>
              </TextBox>

                    <TextBlock Grid.Row="3" Grid.Column="0" Style="{StaticResource smallTitleStyle}" Margin="0,5,0,5">Start Date:</TextBlock>

                    <TextBox Name="StartDateEntryForm" Grid.Row="3" Grid.Column="1" 
                        Validation.ErrorTemplate="{StaticResource validationTemplate}" 
                        Style="{StaticResource textStyleTextBox}" Margin="8,5,0,5">
                        <TextBox.Text>
                            <Binding Path="StartDate" UpdateSourceTrigger="PropertyChanged" 
                                Converter="{StaticResource dateConverter}" >
                                <Binding.ValidationRules>
                                    <src:FutureDateRule />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>

                    <TextBlock Grid.Row="4" Grid.Column="0" Style="{StaticResource smallTitleStyle}" Margin="0,5,0,5">Category:</TextBlock>
                    <ComboBox Name="CategoryEntryForm" Grid.Row="4" Grid.Column="1" 
                        SelectedValue="{Binding Path=Category}" 
                        Style="{StaticResource comboBoxStyle}" ItemContainerStyle="{StaticResource comboBoxItemStyle}" Margin="8,5,0,5">
                        <src:ProductCategory>Books</src:ProductCategory>
                        <src:ProductCategory>Computers</src:ProductCategory>
                        <src:ProductCategory>DVDs</src:ProductCategory>
                        <src:ProductCategory>Electronics</src:ProductCategory>
                        <src:ProductCategory>Home</src:ProductCategory>
                        <src:ProductCategory>Sports</src:ProductCategory>
                    </ComboBox>

                    <TextBlock Grid.Row="5" Grid.Column="0" Style="{StaticResource smallTitleStyle}" Margin="0,5,0,5">Special Features:</TextBlock>
                    <ComboBox Name="SpecialFeaturesEntryForm" Grid.Row="5" Grid.Column="1" 
                        SelectedValue="{Binding Path=SpecialFeatures}" 
                        Style="{StaticResource comboBoxStyle}" ItemContainerStyle="{StaticResource comboBoxItemStyle}" Margin="8,5,0,5">
                        <src:SpecialFeatures>None</src:SpecialFeatures>
                        <src:SpecialFeatures>Color</src:SpecialFeatures>
                        <src:SpecialFeatures>Highlight</src:SpecialFeatures>
                        <ComboBox.IsEnabled>
                            <MultiBinding Converter="{StaticResource specialFeaturesConverter}">
                                <Binding Path="CurrentUser.Rating" 
                                  Source="{x:Static Application.Current}"/>
                                <Binding Path="CurrentUser.MemberSince" 
                            Source="{x:Static Application.Current}"/>
                            </MultiBinding>
                        </ComboBox.IsEnabled>
                    </ComboBox>

                    <Button Name="Submit" Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right" Content="Submit" Margin="5" Click="SubmitProduct"/>
                </Grid>
            </Border>
            <ContentControl Name="ShortPreview" Grid.Row="1" 
                Content="{Binding}" 
                HorizontalAlignment="Left"/>
            <ContentControl Name="LongPreview" Grid.Row="2" 
                Content="{Binding}" 
                ContentTemplate="{StaticResource detailsProductListingTemplate}"
                HorizontalAlignment="Left"/>
        </Grid>
    </Border>
</Window>
